package cn.springboot.controller;

import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.springboot.config.SysConfig;
import cn.springboot.entity.Arcticle;
import cn.springboot.utils.LuceneUtils;

/**
 * @author liufl E-mail:Huberier@allpyra.com
 * @version 创建时间：2017年9月27日 下午2:30:25
 * 类说明
 */
@Controller  
public class SearchController {  
    //索引目录  
    public final static String indexDir=SysConfig.CSDN_INDEX;  
    
    @ResponseBody
    @RequestMapping("search")  
    public List<Arcticle> search(String key,HttpServletResponse rsp) throws Exception{  
        rsp.setHeader("Content-Type", "application/json;charset=UTF-8");  
        return LuceneUtils.search(indexDir, key);  
    }  
    

    /**
     * spring-boot下，默认约定了Controller试图跳转中thymeleaf模板文件的的前缀prefix是”classpath:/templates/”,后缀suffix是”.html” 
     * 可以修改   spring.thymeleaf.prefix: /templates/    
				spring.thymeleaf.suffix: .html  
     * @param model
     * @return
     * @throws Exception
     */
    @GetMapping("/spliderHome")  
    public String spliderHome(){
        return "jsoups";  
    }  
    @GetMapping("/test")  
    public String test(HashMap<String,Object> map){
        map.put("userName","豆子");
        return "test";  
    }  
} 

